/**
 * 
 */
package com.tomkid.naojin.acts;

import com.tomkid.naojin.utils.CConstance;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;

/**
 * 5485 jokes
 * 
 * @author zhao.tb
 */
public class DetailsOneActivity extends BaseActivity implements View.OnClickListener{
	private String[] mArrayQuestions = null;
	private String[] mArrayAnswers = null;
	private int mCurIndex = 0;

	/** UIs */
	private TextView mTV_Number = null;
	private Button mBtn_BackToMain = null;
	private ToggleButton mTg_SaveFavor = null;
	private TextView mTV_Question = null;
	private ToggleButton mTg_ShowAnswer = null;
	private TextView mTV_Answer = null;
	private Button mBtn_Prev = null;
	private Button mBtn_Next = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.details_one);
		mArrayAnswers = getResources().getStringArray(R.array.array_Answers);
		mArrayQuestions = getResources().getStringArray(R.array.array_Questions);

		Bundle b = getIntent().getExtras();
		if(b != null){
			mCurIndex = b.getInt("no",0);
		}
		mTV_Answer = (TextView) findViewById(R.id.tv_answer);
		mTV_Number = (TextView) findViewById(R.id.tv_number);
		mTV_Question = (TextView) findViewById(R.id.tv_question);
		mBtn_BackToMain = (Button) findViewById(R.id.btn_BackToMain);
		mBtn_Next = (Button) findViewById(R.id.btn_next);
		mBtn_Prev = (Button) findViewById(R.id.btn_prev);
		mTg_SaveFavor = (ToggleButton) findViewById(R.id.btn_savefavor);
		mTg_ShowAnswer = (ToggleButton) findViewById(R.id.toggleButton1);
		
		//init
		mTV_Answer.setText(mArrayAnswers[mCurIndex]);
		mTV_Number.setText(""+(mCurIndex+1));
		mTV_Question.setText(mArrayQuestions[mCurIndex]);
		if(mTg_ShowAnswer.isChecked()){
			mTV_Answer.setVisibility(View.VISIBLE);
		}else{
			mTV_Answer.setVisibility(View.INVISIBLE);
		}
	}

	private void setContent(){
		mTV_Answer.setText(mArrayAnswers[mCurIndex]);
		mTV_Number.setText(""+(mCurIndex+1));
		mTV_Question.setText(mArrayQuestions[mCurIndex]);
		mTg_ShowAnswer.setChecked(false);
		mTV_Answer.setVisibility(View.INVISIBLE);
	}
	
	/* (Override)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch(id){
			case R.id.btn_BackToMain:
				Intent i = new Intent(DetailsOneActivity.this,MainTabsActivity.class);
				startActivity(i, false);
				finish();
				break;
			case R.id.toggleButton1:
				if(mTg_ShowAnswer.isChecked()){
					mTV_Answer.setVisibility(View.VISIBLE);
				}else{
					mTV_Answer.setVisibility(View.INVISIBLE);
				}
				break;
			case R.id.btn_next:
				mCurIndex = (mCurIndex+1)%CConstance.TotalNumber;
				setContent();
				break;
			case R.id.btn_prev:
				if(mCurIndex > 0){
					mCurIndex = (mCurIndex-1)%CConstance.TotalNumber;
					setContent();
				}
				break;
			case R.id.btn_savefavor:
				
				break;
			default:
				break;
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
